<template>
  <label class="switch">
    <input v-model="modelValue" type="checkbox" :disabled="disabled" />
    <span class="slider round" :class="[inputBg, disabled ? 'disabledBg ' : '']"></span>
  </label>
</template>
<script setup>
import { computed } from 'vue'

const emit = defineEmits(['update:modelValue'])
const props = defineProps({
  modelValue: {
    type: Boolean,
    default: false,
  },
  inputBg: {
    type: String,
    default: 'defaultBg', // defaultBg | popupBg
  },
  disabled: {
    type: Boolean,
    default: false,
  },
})

const modelValue = computed({
  get: () => props.modelValue,
  set: (value) => emit('update:modelValue', value),
})
</script>
<style scoped lang="scss">
.switch {
  position: relative;
  display: inline-block;

  width: 2.2125rem;
  height: 1.25rem;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 2.3125rem;
  -webkit-transition: 0.4s;
  transition: 0.4s;
  border-radius: 62.5rem;
  border: none;
}

.defaultBg {
  background: rgb(var(--v-theme-surface));
}

.popupBg {
  background: rgb(var(--v-theme-background));
}

.disabledBg {
  background: black;
  opacity: 0.5;
}

.slider:before {
  position: absolute;
  content: '';
  height: 1rem;
  width: 1rem;
  bottom: 0.1275rem;
  left: 0.15rem;
  background-color: white;
  -webkit-transition: 0.4s;
  transition: 0.4s;
}

input:checked + .slider {
  background-color: #ff4d67;
}

input:focus + .slider {
  box-shadow: none;
}

input:checked + .slider:before {
  -webkit-transform: translateX(0.99rem);
  -ms-transform: translateX(0.99rem);
  transform: translateX(0.99rem);
}

/* Rounded sliders */
.slider.round {
  border-radius: 62.5rem;
}

.slider.round:before {
  border-radius: 62.5rem;
}
</style>
